VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Obj"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Const MAXCLASSES = 6
Function ClassCompleted(conn As ADODB.Connection, lngStudentID As Long, strClassID As String) As Boolean
    Dim rsEnrollment As Object
    Dim strSQL As String
    
    'Student cannot drop a class if the class is completed
    'In other words, it has a grade
    strSQL = "select classid,studentid,grade from enrollment where studentid = " & lngStudentID & " AND classid ='" & strClassID & "'"
    Set rsEnrollment = conn.Execute(strSQL)
    
    'Check for no records even existing
    If rsEnrollment.BOF And rsEnrollment.EOF Then
       ClassCompleted = False
       Exit Function
    End If
    
    'Check for a non-null grade
    If Not IsNull(rsEnrollment.Fields("Grade")) Then
        ClassCompleted = True
    Else
        ClassCompleted = False
    End If
    rsEnrollment.Close
End Function
Public Function Drop(ByVal lngStudentID As Long, ByVal strClassID As String) As Integer
    Dim ctxObject As ObjectContext
    Dim conn As ADODB.Connection
    Dim strSQL As String
    
    On Error GoTo ErrorHandler
    Drop = 0
    ' Get the Context Object
    Set ctxObject = GetObjectContext()
    Set conn = CreateObject("ADODB.connection")

    'Open connection with State University Database
    conn.Open "DSN=StateU;UID=sa;PWD=;"

    'Check business rule
    'Make sure class isn't already completed
    'In which case student cannot drop
    If ClassCompleted(conn, lngStudentID, strClassID) Then
        Drop = 1
        ctxObject.SetAbort
        Exit Function
    End If

    'Perform the work of dropping the student from the class
    strSQL = "DELETE FROM enrollment where ClassID ='" & strClassID & "' AND Studentid =" & lngStudentID
    conn.Execute strSQL

    'Close the connection
    conn.Close

    'Work completed Successfully
    ctxObject.SetComplete
    Exit Function

ErrorHandler:
    Drop = 1
    'Abort if any errors occurred
    ctxObject.SetAbort

End Function

